<%--
    Document   : removeFromCart
    Author     : Thomas
--%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">
<jsp:useBean id="addBookToCartBean" class="beans_pkg.addBookToCartBean" scope="page"/>
<jsp:setProperty name="addBookToCartBean" property="*"/>

<%
    if(session.getAttribute("cart") == null){
        session.setAttribute("cart", "");
    }
    String cart = (String) session.getAttribute("cart");
    String[] cartContents = cart.split(",");
    cart = "";
    for(int i=0; i<cartContents.length; i++){
        if(!cartContents[i].contains(addBookToCartBean.getISBN())){
            cart += cartContents[i] + ",";
        }
    }
    if(cart == ""){
        session.setAttribute("cart", null);
    }
    else{
        session.setAttribute("cart", cart);
    }

    String redirectURL = (String) session.getAttribute("currentPage");
    response.sendRedirect(redirectURL);
%>
